package com.google.gson.b;

import com.sutuijingling.result.WorkStatus;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpStatus;

public class a implements Closeable {
    private static final char[] a = ")]}'\n".toCharArray();
    private final f b = new f();
    private final Reader c;
    private boolean d = false;
    private final char[] e = new char[1024];
    private int f = 0;
    private int g = 0;
    private int h = 1;
    private int i = 1;
    private final List j = new ArrayList();
    private boolean k;
    private c l;
    private String m;
    private String n;
    private boolean o;

    public a(Reader reader) {
        a(b.EMPTY_DOCUMENT);
        this.o = false;
        if (reader == null) {
            throw new NullPointerException("in == null");
        }
        this.c = reader;
    }

    private void A() throws IOException {
        char c;
        do {
            if (this.f < this.g || a(1)) {
                char[] cArr = this.e;
                int i = this.f;
                this.f = i + 1;
                c = cArr[i];
                if (c == '\r') {
                    return;
                }
            } else {
                return;
            }
        } while (c != '\n');
    }

    private String B() throws IOException {
        StringBuilder stringBuilder = null;
        do {
            int i = this.f;
            while (this.f < this.g) {
                char[] cArr = this.e;
                int i2 = this.f;
                this.f = i2 + 1;
                switch (cArr[i2]) {
                    case '\t':
                    case '\n':
                    case '\f':
                    case WorkStatus.ItemMakeOrder /*13*/:
                    case ' ':
                    case ',':
                    case ':':
                    case '[':
                    case ']':
                    case '{':
                    case '}':
                        break;
                    case '#':
                    case '/':
                    case ';':
                    case '=':
                    case '\\':
                        z();
                        break;
                    default:
                }
                this.f--;
                if (this.o) {
                    return "skipped!";
                }
                if (stringBuilder == null) {
                    return this.b.a(this.e, i, this.f - i);
                }
                stringBuilder.append(this.e, i, this.f - i);
                return stringBuilder.toString();
            }
            if (stringBuilder == null) {
                stringBuilder = new StringBuilder();
            }
            stringBuilder.append(this.e, i, this.f - i);
        } while (a(1));
        return stringBuilder.toString();
    }

    private char C() throws IOException {
        if (this.f != this.g || a(1)) {
            char[] cArr = this.e;
            int i = this.f;
            this.f = i + 1;
            char c = cArr[i];
            switch (c) {
                case 'b':
                    return '\b';
                case HttpStatus.SC_PROCESSING /*102*/:
                    return '\f';
                case 'n':
                    return '\n';
                case 'r':
                    return '\r';
                case 't':
                    return '\t';
                case 'u':
                    if (this.f + 4 <= this.g || a(4)) {
                        String a = this.b.a(this.e, this.f, 4);
                        this.f += 4;
                        return (char) Integer.parseInt(a, 16);
                    }
                    throw b("Unterminated escape sequence");
                default:
                    return c;
            }
        }
        throw b("Unterminated escape sequence");
    }

    private c D() throws IOException {
        String B = B();
        if (B.length() == 0) {
            throw b("Expected literal value");
        }
        this.n = B;
        this.k = true;
        this.l = null;
        return null;
    }

    private void E() throws IOException {
        if (this.n.equalsIgnoreCase("null")) {
            this.l = c.NULL;
        } else if (this.n.equalsIgnoreCase("true") || this.n.equalsIgnoreCase("false")) {
            this.l = c.BOOLEAN;
        } else {
            try {
                Double.parseDouble(this.n);
                this.l = c.NUMBER;
            } catch (NumberFormatException e) {
                z();
                this.l = c.STRING;
            }
        }
    }

    private CharSequence F() {
        CharSequence stringBuilder = new StringBuilder();
        int min = Math.min(this.f, 20);
        stringBuilder.append(this.e, this.f - min, min);
        stringBuilder.append(this.e, this.f, Math.min(this.g - this.f, 20));
        return stringBuilder;
    }

    private String a(char c) throws IOException {
        StringBuilder stringBuilder = null;
        do {
            int i = this.f;
            while (this.f < this.g) {
                char[] cArr = this.e;
                int i2 = this.f;
                this.f = i2 + 1;
                char c2 = cArr[i2];
                if (c2 != c) {
                    StringBuilder stringBuilder2;
                    int i3;
                    int i4;
                    if (c2 == '\\') {
                        if (stringBuilder == null) {
                            stringBuilder = new StringBuilder();
                        }
                        stringBuilder.append(this.e, i, (this.f - i) - 1);
                        stringBuilder.append(C());
                        stringBuilder2 = stringBuilder;
                        i3 = this.f;
                    } else {
                        i4 = i;
                        stringBuilder2 = stringBuilder;
                        i3 = i4;
                    }
                    i4 = i3;
                    stringBuilder = stringBuilder2;
                    i = i4;
                } else if (this.o) {
                    return "skipped!";
                } else {
                    if (stringBuilder == null) {
                        return this.b.a(this.e, i, (this.f - i) - 1);
                    }
                    stringBuilder.append(this.e, i, (this.f - i) - 1);
                    return stringBuilder.toString();
                }
            }
            if (stringBuilder == null) {
                stringBuilder = new StringBuilder();
            }
            stringBuilder.append(this.e, i, this.f - i);
        } while (a(1));
        throw b("Unterminated string");
    }

    private void a(b bVar) {
        this.j.add(bVar);
    }

    private void a(c cVar) throws IOException {
        p();
        if (this.l != cVar) {
            throw new IllegalStateException("Expected " + cVar + " but was " + f());
        }
        r();
    }

    private boolean a(int i) throws IOException {
        int i2;
        for (i2 = 0; i2 < this.f; i2++) {
            if (this.e[i2] == '\n') {
                this.h++;
                this.i = 1;
            } else {
                this.i++;
            }
        }
        if (this.g != this.f) {
            this.g -= this.f;
            System.arraycopy(this.e, this.f, this.e, 0, this.g);
        } else {
            this.g = 0;
        }
        this.f = 0;
        do {
            i2 = this.c.read(this.e, this.g, this.e.length - this.g);
            if (i2 == -1) {
                return false;
            }
            this.g = i2 + this.g;
            if (this.h == 1 && this.i == 1 && this.g > 0 && this.e[0] == '﻿') {
                this.f++;
                this.i--;
            }
        } while (this.g < i);
        return true;
    }

    private boolean a(String str) throws IOException {
        while (true) {
            if (this.f + str.length() > this.g && !a(str.length())) {
                return false;
            }
            int i = 0;
            while (i < str.length()) {
                if (this.e[this.f + i] != str.charAt(i)) {
                    this.f++;
                } else {
                    i++;
                }
            }
            return true;
        }
    }

    private c b(boolean z) throws IOException {
        c cVar;
        if (z) {
            b(b.NONEMPTY_ARRAY);
        } else {
            switch (y()) {
                case 44:
                    break;
                case 59:
                    z();
                    break;
                case 93:
                    t();
                    this.k = true;
                    cVar = c.END_ARRAY;
                    this.l = cVar;
                    return cVar;
                default:
                    throw b("Unterminated array");
            }
        }
        switch (y()) {
            case 44:
            case 59:
                break;
            case 93:
                if (z) {
                    t();
                    this.k = true;
                    cVar = c.END_ARRAY;
                    this.l = cVar;
                    return cVar;
                }
                break;
            default:
                this.f--;
                return v();
        }
        z();
        this.f--;
        this.k = true;
        this.n = "null";
        cVar = c.NULL;
        this.l = cVar;
        return cVar;
    }

    private IOException b(String str) throws IOException {
        throw new e(str + " at line " + w() + " column " + x());
    }

    private void b(b bVar) {
        this.j.set(this.j.size() - 1, bVar);
    }

    private c c(boolean z) throws IOException {
        c cVar;
        if (z) {
            switch (y()) {
                case 125:
                    t();
                    this.k = true;
                    cVar = c.END_OBJECT;
                    this.l = cVar;
                    return cVar;
                default:
                    this.f--;
                    break;
            }
        }
        switch (y()) {
            case 44:
            case 59:
                break;
            case 125:
                t();
                this.k = true;
                cVar = c.END_OBJECT;
                this.l = cVar;
                return cVar;
            default:
                throw b("Unterminated object");
        }
        int y = y();
        switch (y) {
            case 34:
                break;
            case 39:
                z();
                break;
            default:
                z();
                this.f--;
                this.m = B();
                if (this.m.length() == 0) {
                    throw b("Expected name");
                }
                break;
        }
        this.m = a((char) y);
        b(b.DANGLING_NAME);
        this.k = true;
        cVar = c.NAME;
        this.l = cVar;
        return cVar;
    }

    private c p() throws IOException {
        if (this.k) {
            return this.l;
        }
        c v;
        switch (s()) {
            case EMPTY_DOCUMENT:
                if (this.d) {
                    q();
                }
                b(b.NONEMPTY_DOCUMENT);
                v = v();
                if (this.d || v == c.BEGIN_ARRAY || v == c.BEGIN_OBJECT) {
                    return v;
                }
                b("Expected JSON document to start with '[' or '{'");
                return v;
            case EMPTY_ARRAY:
                return b(true);
            case NONEMPTY_ARRAY:
                return b(false);
            case EMPTY_OBJECT:
                return c(true);
            case DANGLING_NAME:
                return u();
            case NONEMPTY_OBJECT:
                return c(false);
            case NONEMPTY_DOCUMENT:
                try {
                    v = v();
                    if (this.d) {
                        return v;
                    }
                    throw b("Expected EOF");
                } catch (EOFException e) {
                    this.k = true;
                    v = c.END_DOCUMENT;
                    this.l = v;
                    return v;
                }
            case CLOSED:
                throw new IllegalStateException("JsonReader is closed");
            default:
                throw new AssertionError();
        }
    }

    private void q() throws IOException {
        y();
        this.f--;
        if (this.f + a.length <= this.g || a(a.length)) {
            int i = 0;
            while (i < a.length) {
                if (this.e[this.f + i] == a[i]) {
                    i++;
                } else {
                    return;
                }
            }
            this.f += a.length;
        }
    }

    private c r() throws IOException {
        p();
        c cVar = this.l;
        this.k = false;
        this.l = null;
        this.n = null;
        this.m = null;
        return cVar;
    }

    private b s() {
        return (b) this.j.get(this.j.size() - 1);
    }

    private b t() {
        return (b) this.j.remove(this.j.size() - 1);
    }

    private c u() throws IOException {
        switch (y()) {
            case 58:
                break;
            case 61:
                z();
                if ((this.f < this.g || a(1)) && this.e[this.f] == '>') {
                    this.f++;
                    break;
                }
            default:
                throw b("Expected ':'");
        }
        b(b.NONEMPTY_OBJECT);
        return v();
    }

    private c v() throws IOException {
        c cVar;
        int y = y();
        switch (y) {
            case 34:
                break;
            case 39:
                z();
                break;
            case 91:
                a(b.EMPTY_ARRAY);
                this.k = true;
                cVar = c.BEGIN_ARRAY;
                this.l = cVar;
                return cVar;
            case 123:
                a(b.EMPTY_OBJECT);
                this.k = true;
                cVar = c.BEGIN_OBJECT;
                this.l = cVar;
                return cVar;
            default:
                this.f--;
                return D();
        }
        this.n = a((char) y);
        this.k = true;
        cVar = c.STRING;
        this.l = cVar;
        return cVar;
    }

    private int w() {
        int i = this.h;
        for (int i2 = 0; i2 < this.f; i2++) {
            if (this.e[i2] == '\n') {
                i++;
            }
        }
        return i;
    }

    private int x() {
        int i = this.i;
        for (int i2 = 0; i2 < this.f; i2++) {
            i = this.e[i2] == '\n' ? 1 : i + 1;
        }
        return i;
    }

    private int y() throws IOException {
        while (true) {
            if (this.f < this.g || a(1)) {
                char[] cArr = this.e;
                int i = this.f;
                this.f = i + 1;
                char c = cArr[i];
                switch (c) {
                    case '\t':
                    case '\n':
                    case WorkStatus.ItemMakeOrder /*13*/:
                    case ' ':
                        break;
                    case '#':
                        z();
                        A();
                        continue;
                    case '/':
                        if (this.f == this.g && !a(1)) {
                            break;
                        }
                        z();
                        switch (this.e[this.f]) {
                            case '*':
                                this.f++;
                                if (a("*/")) {
                                    this.f += 2;
                                    continue;
                                    continue;
                                } else {
                                    throw b("Unterminated comment");
                                }
                            case '/':
                                this.f++;
                                A();
                                continue;
                            default:
                                break;
                        }
                    default:
                        break;
                }
                return c;
            }
            throw new EOFException("End of input");
        }
    }

    private void z() throws IOException {
        if (!this.d) {
            throw b("Use JsonReader.setLenient(true) to accept malformed JSON");
        }
    }

    public void a() throws IOException {
        a(c.BEGIN_ARRAY);
    }

    public final void a(boolean z) {
        this.d = z;
    }

    public void b() throws IOException {
        a(c.END_ARRAY);
    }

    public void c() throws IOException {
        a(c.BEGIN_OBJECT);
    }

    public void close() throws IOException {
        this.k = false;
        this.n = null;
        this.l = null;
        this.j.clear();
        this.j.add(b.CLOSED);
        this.c.close();
    }

    public void d() throws IOException {
        a(c.END_OBJECT);
    }

    public boolean e() throws IOException {
        p();
        return (this.l == c.END_OBJECT || this.l == c.END_ARRAY) ? false : true;
    }

    public c f() throws IOException {
        p();
        if (this.l == null) {
            E();
        }
        return this.l;
    }

    public String g() throws IOException {
        p();
        if (this.l != c.NAME) {
            throw new IllegalStateException("Expected a name but was " + f());
        }
        String str = this.m;
        r();
        return str;
    }

    public String h() throws IOException {
        f();
        if (this.n == null || !(this.l == c.STRING || this.l == c.NUMBER)) {
            throw new IllegalStateException("Expected a string but was " + f());
        }
        String str = this.n;
        r();
        return str;
    }

    public boolean i() throws IOException {
        p();
        if (this.n == null || this.l == c.STRING) {
            throw new IllegalStateException("Expected a boolean but was " + f());
        }
        boolean z;
        if (this.n.equalsIgnoreCase("true")) {
            z = true;
        } else if (this.n.equalsIgnoreCase("false")) {
            z = false;
        } else {
            throw new IllegalStateException("Not a boolean: " + this.n);
        }
        r();
        return z;
    }

    public void j() throws IOException {
        p();
        if (this.n == null || this.l == c.STRING) {
            throw new IllegalStateException("Expected null but was " + f());
        } else if (this.n.equalsIgnoreCase("null")) {
            r();
        } else {
            throw new IllegalStateException("Not a null: " + this.n);
        }
    }

    public double k() throws IOException {
        p();
        if (this.n == null) {
            throw new IllegalStateException("Expected a double but was " + f());
        }
        double parseDouble = Double.parseDouble(this.n);
        if (parseDouble >= 1.0d && this.n.startsWith("0")) {
            throw new NumberFormatException("JSON forbids octal prefixes: " + this.n);
        } else if (this.d || !(Double.isNaN(parseDouble) || Double.isInfinite(parseDouble))) {
            r();
            return parseDouble;
        } else {
            throw new NumberFormatException("JSON forbids NaN and infinities: " + this.n);
        }
    }

    public long l() throws IOException {
        long parseLong;
        p();
        if (this.n == null) {
            throw new IllegalStateException("Expected a long but was " + f());
        }
        try {
            parseLong = Long.parseLong(this.n);
        } catch (NumberFormatException e) {
            double parseDouble = Double.parseDouble(this.n);
            parseLong = (long) parseDouble;
            if (((double) parseLong) != parseDouble) {
                throw new NumberFormatException(this.n);
            }
        }
        if (parseLong < 1 || !this.n.startsWith("0")) {
            r();
            return parseLong;
        }
        throw new NumberFormatException("JSON forbids octal prefixes: " + this.n);
    }

    public int m() throws IOException {
        int parseInt;
        p();
        if (this.n == null) {
            throw new IllegalStateException("Expected an int but was " + f());
        }
        try {
            parseInt = Integer.parseInt(this.n);
        } catch (NumberFormatException e) {
            double parseDouble = Double.parseDouble(this.n);
            parseInt = (int) parseDouble;
            if (((double) parseInt) != parseDouble) {
                throw new NumberFormatException(this.n);
            }
        }
        if (((long) parseInt) < 1 || !this.n.startsWith("0")) {
            r();
            return parseInt;
        }
        throw new NumberFormatException("JSON forbids octal prefixes: " + this.n);
    }

    public void n() throws IOException {
        this.o = true;
        int i = 0;
        while (true) {
            try {
                c r = r();
                if (r == c.BEGIN_ARRAY || r == c.BEGIN_OBJECT) {
                    i++;
                    continue;
                } else if (r == c.END_ARRAY || r == c.END_OBJECT) {
                    i--;
                    continue;
                }
                if (i == 0) {
                    break;
                }
            } finally {
                this.o = false;
            }
        }
    }

    public final boolean o() {
        return this.d;
    }

    public String toString() {
        return getClass().getSimpleName() + " near " + F();
    }
}
